<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
global $curruser;
include( "class/class.Bnowconfig.php" );
$Bnowconfig = new Bnowconfig(0, $curruser['id']);
$user = new User();
$ui = new UI();
$conf = new Config();
$starbet = $conf->get("startbet");
$stopbet = $conf->get("stopbet");
$editportmod = intval($conf->get("edit_autoprot_mod"));
include( "member/news.php" );
$tpl = new Template2();
$editmode = 1;
$lotto_id = 0;
$psen_edit_mod = 1;
$rs = getdb("select id,open from lotto where open>='" . date("Y-m-d") . "' order by open");
if (!$rs->eof)
{
    $lotto_id = intval($rs->f['id']);
    $open = $rs->f['open'];
    if (date("Y-m-d") == $open)
    {
        $stopbet = $conf->get("stopbet");
        if ($conf->get("startbet") <= date("Hi") && date("Hi") <= $stopbet)
        {
            $psen_edit_mod = $editportmod;
        }
    }
    $users = GetUserList($curruser['id']);
    if ($users != "")
    {
        $rs = getdb("select sum(amount) from bet where user_id in (" . $users . ") and lotto_id=" . $lotto_id . " and rame=0");
        if ($rs->f[0] + 0 == 0)
        {
            $psen_edit_mod = 1;
        }
        $rs->close();
    }
    else
    {
        $psen_edit_mod = 0;
    }
}
$rs->close();
if (getvar("chgpasswd") != "")
{
    if ($user->ChangePassword(getvar("chgpasswd")) == false)
    {
        $tpl->set("msg", L_CHGPWDFAIL);
    }
    else
    {
        $tpl->set("msg", L_CHGPWDSUCC);
    }
}
$theacl = $curruser['acl'];
$alert1 = $curruser['alert1'];
$alert2 = $curruser['alert2'];
$alert41 = $curruser['alert41'];
$alert42 = $curruser['alert42'];
$alert0_old = min(0 - 5000, $Bnowconfig->getVal("alert0"));
$alert40_old = min(0 - 5000, $Bnowconfig->getVal("alert40"));
$alert0 = $alert0_old;
$alert40 = $alert40_old;
if (isset($_POST['alert0']) || isset($_POST['alert40']) || isset($_POST['alert1']) || isset($_POST['alert2']) || isset($_POST['alert41']) || isset($_POST['alert42']))
{
    if (isset($_POST['alert0']))
    {
        $alert0 = intval($_POST['alert0']);
    }
    if (isset($_POST['alert40']))
    {
        $alert40 = intval($_POST['alert40']);
    }
    if (0 < $alert0)
    {
        $alert0 = 0 - $alert0;
    }
    if (0 < $alert40)
    {
        $alert40 = 0 - $alert40;
    }
    if ($editmode == 1)
    {
        if ($alert0_old < $alert0)
        {
            $alert0 = min(0 - 5000, $alert0);
        }
        if ($alert40_old < $alert40)
        {
            $alert40 = min(0 - 2000, $alert40);
        }
    }
    if (isset($_POST['alert1']))
    {
        $alert1 = intval($_POST['alert1']);
    }
    if (isset($_POST['alert2']))
    {
        $alert2 = intval($_POST['alert2']);
    }
    if (isset($_POST['alert41']))
    {
        $alert41 = intval($_POST['alert41']);
    }
    if (isset($_POST['alert42']))
    {
        $alert42 = intval($_POST['alert42']);
    }
    getdb("update k_user set alert0=" . $alert0 . ", alert1=" . $alert1 . ", alert2=" . $alert2 . ", alert40=" . $alert40 . ", alert41=" . $alert41 . ", alert42=" . $alert42 . " where id=" . $curruser['id']);
    $Bnowconfig->setVal("alert0", $alert0);
    $Bnowconfig->setVal("alert40", $alert40);
}
$tpl->load(array("main" => "info.htm"));
$tpl->set("account", $curruser['account']);
$tpl->set("name", $curruser['name']);
$tpl->set("amount", number_format($curruser['amount']));
$percent = 1;
if ($theacl == 2)
{
    $percent = $curruser['mpercent'];
    $tpl->set("percent", "<tr><td class=td0>最低占成<td class=td2>" . $percent . "%");
}
$protmod = 0;
if ($theacl == 2)
{
    $u_genagent = get_user($curruser['prev_id']);
    $u_shareowner = get_user($u_genagent['prev_id']);
    $u_subsidary = get_user($u_shareowner['prev_id']);
    $protmod = $u_subsidary['protmod'];
}
else if ($theacl == 3)
{
    $u_shareowner = get_user($curruser['prev_id']);
    $u_subsidary = get_user($u_shareowner['prev_id']);
    $protmod = $u_subsidary['protmod'];
}
else
{
    if ($theacl == 4)
    {
        $u_subsidary = get_user($curruser['prev_id']);
        $protmod = $u_subsidary['protmod'];
    }
    else
    {
        if ($curruser['percent_sw'] == 1)
        {
            $protmod = 0;
            $psen_edit_mod = 0;
        }
        $protmod = $curruser['protmod'];
    }
}
if (0 < $psen_edit_mod && 0 < $protmod && isset($_POST['auto_ok']))
{
    $myamount = GetAmountSetting($curruser['id'], 0, 0);
    foreach ($myamount as $key => $value)
    {
        if (isset($_POST["autont" . $key]))
        {
            $auto_nt = intval($_POST["autont" . $key]);
            if ($auto_nt != $myamount[$key]['auto_nt'])
            {
                $subid = 0;
                if (270 < $key)
                {
                    $subid = $myamount[$key]['subid'];
                    $key = substr(strval($key), 0, 2);
                }
                $sql = "update amounts set auto_nt=" . $auto_nt . " ,updateid=" . $curruser['id'] . " ,updatedt='" . date("Y-m-d H:i:s") . "' where user_id=" . $curruser['id'] . " and bettype=" . $key . " and subid=" . $subid;
                getdb($sql);
            }
        }
    }
}
$myamount = GetAmountSetting($curruser['id'], 0, 0);
$autorate_mode = 0 < $protmod && 0 < $psen_edit_mod;
$chk_autont = 0;
$list = "";

foreach ($g_betname as $key => $value)
{
    $begin = $key;
    $end = $key;
    if ($key == 27)
    {
        $begin = 272;
        $end = 275;
    }
    else if ($key == 36)
    {
        $begin = 362;
        $end = 365;
    }
    $ii = $begin;
    while ($ii <= $end)
    {
        $key = $ii;
        $list .= "<tr class=td2>";
        switch ($key)
        {
            case 272 :
            case 273 :
            case 274 :
            case 275 :
                $list .= "<td class=td6>" . $value . ( $key - 270 );
                break;
            case 362 :
            case 363 :
            case 364 :
			case 365 :
                $list .= "<td class=td6>" . $value . ( $key - 360 );
                break;
            default :
                $list .= "<td class=td6>" . $value;
                break;
        }
        if ($myamount[$key][2] == 0)
        {
            $list .= "<td nowrap align=right> -";
            $list .= "<td nowrap align=right> -";
            $list .= "<td nowrap align=right> -";
            $list .= "<td nowrap align=right> -";
            $list .= "<td nowrap align=right> -";
            $list .= "<td nowrap align=right> -";
            if (0 < $protmod)
            {
                $list .= "<td nowrap align=right> -<td nowrap align=right> -";
            }
        }
        else
        {
            $list .= "<td nowrap align=right>" . round(100 - $myamount[$key]['back1'], 2);
            $list .= "<td nowrap align=right>" . round(100 - $myamount[$key]['back2'], 2);
            $list .= "<td nowrap align=right>" . round(100 - $myamount[$key]['back3'], 2);
            $list .= "<td nowrap align=right>" . round(100 - $myamount[$key]['back4'], 2);
            if ($key == 24 || $key == 26 || $key == 31 || $key == 32 || $key == 33 || $key == 37 || $key == 38)
            {
                $list .= "<td nowrap align=right><font color=red> *</font>";
                $list .= "<td nowrap align=right><font color=red> *</font>";
                if ($autorate_mode)
                {
                    $list .= "<td nowrap align=right><font color=red> *</font>";
                    if ($key == 24)
                    {
                        $list .= "<input type=hidden name=autont24 value=" . $myamount[0]['auto_nt'] . ">";
                    }
                    else if ($key == 26)
                    {
                        $list .= "<input type=hidden name=autont26 value=" . $myamount[25]['auto_nt'] . ">";
                    }
                    else if ($key == 31)
                    {
                        $list .= "<input type=hidden name=autont31 value=" . $myamount[4]['auto_nt'] . ">";
                    }
                    else if ($key == 32)
                    {
                        $list .= "<input type=hidden name=autont32 value=" . $myamount[10]['auto_nt'] . ">";
                    }
                    else if ($key == 33)
                    {
                        $list .= "<input type=hidden name=autont33 value=" . $myamount[9]['auto_nt'] . ">";
                    }
                    else if ($key == 37)
                    {
                        $list .= "<input type=hidden name=autont37 value=" . $myamount[21]['auto_nt'] . ">";
                    }
                    else if ($key == 38)
                    {
                        $list .= "<input type=hidden name=autont38 value=" . $myamount[22]['auto_nt'] . ">";
                    }
                    $list .= "<td nowrap align=right><font color=red> *</font>";
                }
            }
            else
            {
                $list .= "<td nowrap align=right>" . number_format($myamount[$key][2]);
                $list .= "<td nowrap align=right>" . number_format($myamount[$key][1]);
                if (0 < $protmod)
                {
                    if ($key == 12)
                    {
                        $list .= "<td nowrap align=right> -<td nowrap align=right> -";
                    }
                    else
                    {
                        if (0 < $psen_edit_mod)
                        {
                            $list .= "<td nowrap align=right><input name=autont" . $key . " value=" . $myamount[$key]['auto_nt'] . " onkeypress=\"return OnlyInt()\" size=5>";
                        }
                        else
                        {
                            $list .= "<td nowrap align=right>" . $myamount[$key]['auto_nt'];
                        }
                        $list .= "<td nowrap align=right>" . $myamount[$key]['updatedt'];
                        ++$chk_autont;
                    }
                }
            }
        }
        ++$ii;
    }
}
if (0 < $protmod && 0 < $chk_autont)
{
    $list .= "<input type=hidden name=auto_ok value=1>";
    $tpl->set("tableexc1", "<td class=td0 width='14%'>自动走飞设定</td>");
    $tpl->set("tableexc2", "<td class=td0 width='22%'>最後修改的日期 时间</td>");
    if (0 < $psen_edit_mod)
    {
        $tpl->set("rottexc", "<font color=red>※ 自动走飞金额为 0 代表该项目不启动自动走飞！</font>");
    }
    else
    {
        $tpl->set("rottexc", "<font color=red>※ 开盘中禁止设置或变更自动走飞金额！</font>");
    }
}
$tpl->set("amountlist", $list);
$alertlist = "";
if (0 < $protmod && 0 < $percent)
{
    $alertlist .= "<input type=hidden name=auto_ok value=1>";
    $alertlist .= "<b>预设走飞风险值</b>";
    $alertlist .= "<table width=100% border=1 cellspacing=0 cellpadding=2 class=table0>";
    $alertlist .= "<tr><td class=td0>特码风险值</td>";
    $alertlist .= "<td class=td2><input name=alert0 value=" . $alert0 . "></td></tr>";
    $alertlist .= "<tr><td class=td0>正码风险值</td>";
    $alertlist .= "<td class=td2><input name=alert40 value=" . $alert40 . "></td></tr>";
    $alertlist .= "</tr></table>";
}
$tpl->set("alert_list", $alertlist);
$tpl->set("alert1", $alert1);
$tpl->set("alert2", $alert2);
$tpl->set("alert41", $alert41);
$tpl->set("alert42", $alert42);
$tpl->show("main");
$ui->footer();
echo "\r\n\r\n";
?>